<template>
  <div>
    <Header></Header>
    <div class="category-page">
      <div class="container">
        <!-- 面包屑 -->
        <div class="breadcrumb">
          <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>{{ category1.name }}</el-breadcrumb-item>
          </el-breadcrumb>
        </div>
        <!-- 轮播图 -->
        <Carousel></Carousel>
        <!--  全部分类 -->
        <div class="sub-list">
          <h3>全部分类</h3>
          <ul>
            <li v-for="good in category1.children" :key="good.id">
              <img :src="good.picture" alt="" />
              <p>{{ good.name }}</p>
            </li>
          </ul>
        </div>
        <!-- 分类列表一 -->
        <div
          class="ref-goods"
          v-for="good in category1.children"
          :key="good.id"
        >
          <div class="head">
            <h3>- {{ good.name }} -</h3>
            <span>查看全部 ></span>
          </div>
          <div class="ref-goods-list">
            <ul>
              <li v-for="goods in good.goods" :key="goods.id">
                <img :src="goods.picture" alt="" />
                <p>{{ goods.name }}</p>
                <p>{{ goods.desc }}</p>
                <p>￥{{ goods.price }}</p>
              </li>
            </ul>
          </div>
        </div>
      </div>
    </div>

    <Footer></Footer>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  mounted() {
    this.getCategoryList();
  },
  computed: {
    ...mapState({
      category1: (state) => state.category.category1,
    }),
  },
  methods: {
    // 获取一级分类的列表
    getCategoryList() {
      this.$store.dispatch("getCategory1", this.$route.query.id);
    },
  },
  // 监听路由id的变化
  watch: {
    "$route.query.id": {
      handler() {
        this.getCategoryList();
      },
    },
  },
};
</script>

<style lang="less" scoped>
.category-page {
  width: 100%;
  background-color: #f5f5f5;
  padding-bottom: 20px;
}
.category-page .breadcrumb {
  height: 72px;
  padding: 30px 0 0 5px;
}
.sub-list {
  height: 260px;
  background-color: #ffffff;
  margin: 20px 0;
  padding: 0 32px;
}
.sub-list h3 {
  display: inline-block;
  width: 100%;
  height: 100px;
  line-height: 100px;
  text-align: center;
  color: #666666;
  font-size: 28px;
}
.sub-list ul {
  display: flex;
  width: 100%;
  height: 160px;
}
.sub-list ul li {
  flex: 1;
  width: 168px;
  height: 140px;
  text-align: center;
}
.sub-list ul li:hover p {
  color: greenyellow;
}
.sub-list ul li img {
  width: 100px;
  height: 100px;
  margin: 0 0 10px 0;
}
.sub-list ul li p {
  display: inline-block;
  width: 100%;
  height: 40px;
  font-size: 16px;
  color: #333333;
}

.ref-goods {
  width: 100%;
  height: 430px;
  background-color: #ffffff;
  margin-bottom: 20px;
}
.ref-goods .head {
  position: relative;
  height: 100px;
  line-height: 100px;
}
.ref-goods .head h3 {
  font-size: 28px;
  text-align: center;
}
.ref-goods .head span {
  position: absolute;
  top: 0;
  right: 30px;
  color: #999999;
}
.ref-goods-list {
  height: 330px;
  padding: 0 65px 30px;
}
.ref-goods-list ul {
  display: flex;
}
.ref-goods-list ul li {
  flex: 1;
  top: 0;
  width: 220px;
  height: 300px;
  padding: 20px 30px;
}
.ref-goods-list ul li:hover {
  box-shadow: 3px 3px 3px rgba(0, 0, 0, 0.2), -3px -3px 3px rgba(0, 0, 0, 0.2);
  top: -10px;
  position: relative;
  transition: all 0.5s linear;
}
.ref-goods-list ul li img {
  width: 160px;
  height: 160px;
}
.ref-goods-list ul li p:nth-child(2) {
  display: block;
  font-size: 16px;
  padding: 10px 0 0 0;
  width: 160px;
  height: 32.4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ref-goods-list ul li p:nth-child(3) {
  display: block;
  font-size: 14px;
  padding: 10px 0 0 0;
  width: 160px;
  height: 29px;
  color: #999999;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ref-goods-list ul li p:nth-child(4) {
  display: block;
  font-size: 20px;
  padding: 10px 0 0 0;
  width: 160px;
  height: 38px;
  color: #cf4444;
}
/deep/ .el-carousel__arrow--left {
  left: 15px;
  background: rgba(0, 0, 0, 0.5);
}
/deep/ .el-carousel__arrow--right {
  background: rgba(0, 0, 0, 0.5);
}
</style>